import React from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

function UseCount({ children }) {
    function UseCom() {
        const token = localStorage.getItem('token')
        const WhileList = ['/login', '/register', '*', '/']
        const { pathname } = useLocation()
        const navigate = useNavigate()
        if (!token && !WhileList.includes(pathname)) {
            navigate('/login')
        }
        return children
    }
    return <UseCom></UseCom>
}

export default UseCount
